package com.hutao.chargingpile.spread.controller.admin;

import com.hanhan.common.result.R;
import com.hutao.chargingpile.spread.pojo.entity.query.GiftQuery;
import com.hutao.chargingpile.spread.pojo.entity.vo.ChargingGiftVo;
import com.hutao.chargingpile.spread.service.ChargingGiftService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;


import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 礼券表 前端控制器
 * </p>
 *
 * @author HuTao
 * @since 2023-03-27
 */
@Api(tags = "礼券管理")
@RestController
@RequestMapping("/admin/mouse/charginggiftcontroller")
@Slf4j
public class ChargingGiftController {

    @Resource
    private ChargingGiftService chargingGiftService;

    @GetMapping("/findall/{page}/{limit}")
    private R findAll(
            @ApiParam(value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(value = "每页条数", required = true)
            @PathVariable Integer limit,
            GiftQuery giftQuery
    ) {
        System.out.println(giftQuery.getGiftName());
        System.out.println(giftQuery.getGiftStatus());
        Map<String, Object> map = new HashMap<>();
        map.put("page", (page - 1) * limit);
        map.put("limit", limit);
        map.put("giftName", giftQuery.getGiftName());
        map.put("giftStatus", giftQuery.getGiftStatus());
        List<ChargingGiftVo> giftVoList = chargingGiftService.findAll(map);
        ArrayList<Integer> integers = new ArrayList<>();
        Integer[] sizes = integers.toArray(new Integer[]{});
        Integer size = 0;
        for (ChargingGiftVo vo:giftVoList) {
            size = size+1;
            integers.add(size);
        }

        Integer count = chargingGiftService.findCount(map);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("giftVoList", giftVoList);
        map2.put("count", count);
        map2.put("sizes", sizes);
        return R.ok().data("map", map2);
    }

}

